package com.jiandan.business.repository.selfservice;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;

import com.jiandan.business.entity.selfservice.CemeteryInfoPlane;
import com.jiandan.business.entity.selfservice.CemeteryRegion;
import com.jiandan.business.entity.selfservice.Machine;
import com.jiandan.business.entity.selfservice.People;
import com.jiandan.business.entity.selfservice.QueryParam;
import com.jiandan.business.util.selfservice.SelfServiceConstants;

// TODO: Auto-generated Javadoc
/**
 * The Class SelfServiceDaoImpl.
 */
public class SelfServiceDaoImpl implements SelfServiceDao {

	/** The sql session. */
	@Autowired
	private SqlSession sqlSession;

	/**
	 * Gets the sql session.
	 * 
	 * @return the sql session
	 */
	public SqlSession getSqlSession() {
		return sqlSession;
	}

	/**
	 * Sets the sql session.
	 * 
	 * @param sqlSession
	 *            the new sql session
	 */
	public void setSqlSession(SqlSession sqlSession) {
		this.sqlSession = sqlSession;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.jiandan.business.repository.selfservice.SelfServiceDao#getAllMachines
	 * ()
	 */
	@Override
	public List<Machine> getAllMachines() {
		return sqlSession.selectList(SelfServiceConstants.DAO_NAMESPACE
				+ "getAllMachines");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.jiandan.business.repository.selfservice.SelfServiceDao#getMachine
	 * (java.lang.Integer)
	 */
	@Override
	public Machine getMachine(Integer id) {
		return sqlSession.selectOne(SelfServiceConstants.DAO_NAMESPACE
				+ "getMachine", id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.jiandan.business.repository.selfservice.SelfServiceDao#pinyinAssociate
	 * (java.lang.String)
	 */
	@Override
	public List<String> pinyinAssociate(String pinyin) {
		return sqlSession.selectList(SelfServiceConstants.DAO_NAMESPACE
				+ "pinyinAssociate", pinyin);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.jiandan.business.repository.selfservice.SelfServiceDao#getAllRegions
	 * ()
	 */
	@Override
	public List<CemeteryRegion> getAllRegionNames() {
		List<CemeteryRegion> regions = sqlSession
				.selectList(SelfServiceConstants.DAO_NAMESPACE
						+ "getAllRegionNames");
		return regions;
	}

	@Override
	public List<CemeteryInfoPlane> getRegionInfo(Integer regionId) {
		Map<String, Integer> param = new HashMap<String, Integer>();
		param.put("regionId", regionId);
		return sqlSession.selectList(SelfServiceConstants.DAO_NAMESPACE
				+ "getRegionInfo", param);
	}

	@Override
	public List<People> findPeoples(QueryParam param) {
		// TODO Auto-generated method stub
		return null;
	}

}
